package office.img;

import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.PNGTranscoder;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 描述
 *
 * @author: zhanglu
 * @date: 2023/11/22 14:31
 * @modify: 修改人信息, 修改内容 2023/11/22 14:31
 */
public class SvgToPngConverter {

    public static void main(String[] args) {
        try {
            // 读取SVG文件
            File svgFile = new File("/Users/zhanglu/Downloads/新文件-5.svg");
            InputStream inputStream = new FileInputStream(svgFile);

            // 创建PNG转码器
            PNGTranscoder transcoder = new PNGTranscoder();

            // 设置转码器输入和输出
            TranscoderInput input = new TranscoderInput(inputStream);
            OutputStream outputStream = new FileOutputStream("/Users/zhanglu/Downloads/新文件-5.png");
            TranscoderOutput output = new TranscoderOutput(outputStream);

            // 执行转码
            transcoder.transcode(input, output);

            // 关闭输入和输出流
            inputStream.close();
            outputStream.close();

            System.out.println("SVG转换为PNG成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
